home *** CD-ROM | disk | FTP | other *** search
- /* virusCheck.h -- Functions for self-diagnosis of virus infections.
- Copyright © 1989 by Michael S. Morton.
- Special thanks to John Norstad and Andrew Levin for advice.
- You may copy, alter, use, and distribute these routines if you
- leave this file unchanged up to this line.
-
- Think C version.
-
- Notes:
- -----
- • You are STRONGLY urged to make non-functional changes to both C
- functions, to discourage the invention of viruses which recognize
- this code and disable it. Specifically:
- - all parameters and local variables are now declared “register”;
- delete the ‘register’ keyword for randomly-chosen variables
- - declare your own variables and pepper the code with assignments
- involving them -- “a = b+c/d*e+f”. (Be sure to avoid division by 0.)
- - reorder pairs of lines which are preceded by this comment:
- You can swap the order of the next two lines
- - test your application (see below) after all these changes
- - remember that you can call this function from more than one place
- in your application
-
- • To calibrate your application:
- - set the application’s calls to vResCheck or vCodeCheck to pass “1”
- for the “report” parameter
- - build a standalone, double-clickable application
- - make sure that you have a debugger installed which can intercept
- calls to DebugStr () -- MacsBug or TMON will do
- - run the application; if you get messages of the form:
- Got count CC for resource type '<type>', instead of <expected>
- Got length LL for resource type '<type>', instead of <expected>
- then change the arguments in your calls to vCodeCheck() and
- vResCheck() to pass CC for count and LL for long
-
- • To test your application’s virus-detection:
- - calibrate it as above
- - change the application’s calls to pass “-1” for reporting
- - build a standalone, double-clickable application
- - use ResEdit to add a CODE resource from anywhere to your application
- - launch the application and make sure it detects and reports infection
- - delete the added CODE resource or build the application again
-
- • Both of these C functions require EITHER a Mac Plus or 512KE or later,
- OR System file 3.2 or later (for the “one deep” resource calls).
- The application must check this before calling these.
- N.B.: I’m not 100% sure that System 3.2 will work on 128K/512K ROM;
- please try it if you expect your application to work on this
- configuration.
-
- • The “report” parameter takes 1 and -1, not 1 and 0, because many
- compilers will compile a parameter 0 in less space than a parameter 1.
-
- • If these functions encounter an unexpected error, they act
- conservatively and assume there’s an infection.
-
- • If you’re working under Think C, the checksum will be different
- depending on whether your application is running as a project or
- as a standalone application.
-
- You may want to use this technique (invented by David Oster, I think)
- which tests whether the Think C environment is present. It relies on
- the fact that your project’s resource file is the current resource file
- when you start up, and it contains no CODE resources.
- if (Count1Resources ('CODE')) -- are we standalone or project?
- if (vCodeCheck (…)) -- standalone: do the check
- { … } -- check failed: report virus
- For this to work, you must have a resource file “project.rsrc”.
-
- • In certain obscure cases, you may find that changing the
- arguments changes the code length. For example, changing:
- vCodeCheck (3, 0L, 1);
- to
- vCodeCheck (3, 12345L, 1);
- will do this. If this is a problem, move the constant out of the
- code with something like:
- static long expected = 12345L;
- vCodeCheck (3, expected, 1);
- */
-
- #ifndef _virusCheck_ /* already seen this */
- #define _virusCheck_ /* yes: don’t define it again */
-
- /* vCodeCheck -- Check for apparent alteration of CODE resources. Return
- TRUE if the count/length do NOT match, meaning an apparent infection.
- */
- extern Boolean vCodeCheck (
- short expectedCount, /* expected number of CODEs */
- long expectedLen, /* expected total size of CODEs */
- short report); /* >0 => report errors to developer */
-
- /* vResCheck -- Check for apparent alteration of resources. Return TRUE if
- the count/length do NOT match, meaning an apparent infection.
- */
- extern Boolean vResCheck (
- ResType type, /* type of resource to sum */
- short expectedCount, /* expected number of resources */
- long expectedLen, /* expected total size of resources */
- short report); /* >0 => report errors to developer */
-
- #endif _virusCheck_
-